package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/activities")
@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    /**
     * 查询列表
     * @param channel
     * @param type
     * @param status
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping
    public Result list(Integer channel,
                       Integer type,
                       Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("查询活动:{},{},{},{},{}",channel,type,status,page,pageSize);
        PageResult<Activity> pageResult =activityService.list(channel ,type,status ,page,pageSize);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("id:{}",id);
        activityService.deleteById(id);
        return Result.success();
    }
    /**
     * 添加活动
     */
    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("添加：{}",activity );
        activityService.add(activity);
        return Result.success();
    }
    /**
     * 根据id查询 活动
     */
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        log.info("id:{}",id);
        Activity activity = activityService.selectById(id);
        return Result.success(activity);
    }
    /**
     * 修改
     */
    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("修改：{}",activity );
        activityService.update(activity);
        return Result.success();
    }
    /**
     * 查询指定类型活动
     */
    @GetMapping("/type/{type}")
    public Result listByType(@PathVariable Integer type){
        log.info("type:{}",type);
        List<Activity> activityList =activityService.listByType(type);
        return Result.success(activityList);
    }
}
